// internal/apps/auth/serializers/role_serializer.go
package serializers

import (
	"star-go-app/internal/apps/auth/models"
)

// CreateRoleRequest 创建角色请求
type CreateRoleRequest struct {
	Name        string   `json:"name" form:"name" binding:"required,min=2,max=50" example:"管理员"`
	Code        string   `json:"code" form:"code" binding:"required,min=2,max=50" example:"admin"`
	Description string   `json:"description" form:"description" binding:"max=200" example:"系统管理员"`
	Permissions []string `json:"permissions" form:"permissions" example:"user:manage,role:manage"`
}

// UpdateRoleRequest 部分更新角色请求
type UpdateRoleRequest struct {
	Name        *string   `json:"name,omitempty" form:"name" binding:"omitempty,min=2,max=50" example:"管理员"`
	Code        *string   `json:"code,omitempty" form:"code" binding:"omitempty,min=2,max=50" example:"admin"`
	Description *string   `json:"description,omitempty" form:"description" binding:"omitempty,max=200" example:"系统管理员"`
	Permissions *[]string `json:"permissions,omitempty" form:"permissions" example:"user:manage,role:manage"`
}

// UpdateRoleWholeRequest 完整更新角色请求
type UpdateRoleWholeRequest struct {
	Name        string   `json:"name" form:"name" binding:"required,min=2,max=50" example:"管理员"`
	Code        string   `json:"code" form:"code" binding:"required,min=2,max=50" example:"admin"`
	Description string   `json:"description" form:"description" binding:"max=200" example:"系统管理员"`
	Permissions []string `json:"permissions" form:"permissions" example:"user:manage,role:manage"`
}

// RoleListRequest 角色列表请求
type RoleListRequest struct {
	Page     int    `form:"page,default=1" binding:"min=1" example:"1"`
	PageSize int    `form:"page_size,default=10" binding:"min=1,max=100" example:"10"`
	Name     string `form:"name" example:"管理员"`
	Code     string `form:"code" example:"admin"`
}

// RoleListResponse 角色列表响应
type RoleListResponse struct {
	List     []*RoleResponse `json:"list"`
	Total    int64           `json:"total"`
	Page     int             `json:"page"`
	PageSize int             `json:"page_size"`
}

// ConvertRoleToResponse 将角色模型转换为响应
func ConvertRoleToResponse(role *models.Role) *RoleResponse {
	return &RoleResponse{
		ID:          uint(role.ID),
		Name:        role.Name,
		Code:        role.Code,
		Description: role.Description,
		Permissions: []string(role.Permissions),
		CreatedAt:   role.CreatedAt,
		UpdatedAt:   role.UpdatedAt,
	}
}

// ConvertRolesToResponse 将角色模型列表转换为响应列表
func ConvertRolesToResponse(roles []*models.Role) []*RoleResponse {
	responses := make([]*RoleResponse, len(roles))
	for i, role := range roles {
		responses[i] = ConvertRoleToResponse(role)
	}
	return responses
}
